package com.dingli.admin.controller;

import com.dingli.admin.service.IUserService;
import com.dingli.framework.entity.User;
import com.dingli.framework.util.Response;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private IUserService iUserService;

    @GetMapping("/list")
    @ApiOperation("用户信息列表查询")
    public Response<PageInfo<User>> list(@ApiParam("查询条件")
                                         @RequestParam(required = false) String search,
                                         @ApiParam("页码") @RequestParam(required = false) Integer pageNum,
                                         @ApiParam("页面大小")
                                         @RequestParam(required = false) Integer pageSize) {
        return iUserService.list(search, pageNum, pageSize);
    }

    @PostMapping("/insert")
    @ApiOperation("用户信息新增")
    public Object insert(@ApiParam("用户信息") @RequestBody User user) {
        return iUserService.insert(user);
    }

    @GetMapping("/selectById")
    @ApiOperation("用户详情查看")
    public Response<User> selectById(@ApiParam("用户ID") @RequestParam Long userId) {
        return iUserService.selectById(userId);
    }

    @PostMapping("/updateById")
    @ApiOperation("用户信息修改")
    public Response<Object> updateById(@ApiParam("修改的用户信息") @RequestBody User user) {
        return iUserService.updateById(user);
    }

    @GetMapping("/deleteById")
    @ApiOperation("指定用户信息删除")
    public Response<Object> deleteById(@ApiParam("用户ID") @RequestParam Long userId) {
        return iUserService.deleteById(userId);
    }

    @PostMapping("/deleteBatch")
    @ApiOperation("用户信息批量删除")
    public Response<Object> deleteBatch(@ApiParam("用户ID集合") @RequestBody List<Long> idList) {
        return iUserService.deleteBatch(idList);
    }

}
